package com.huang.controller;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 测试sentinel监控
 * @author han
 * @since 2022-01-10 12:12:53
 */
@RestController
public class FlowLimitController {

    private static final Logger logger = LoggerFactory.getLogger(FlowLimitController.class);

    @GetMapping("testA")
    public String testA() {
        logger.info("=======testA");
        return "testA";
    }

    @GetMapping("testB")
    @SentinelResource(value = "testB", blockHandler = "dea_testB")
    public String testB(@RequestParam(required = false, value = "p1") String p1) {
        logger.info("=======testB===>" + p1);
        return "testB";
    }

    public String dea_testB(String p1, BlockException e) {
        logger.info("=======dea_testB===>" + e.getMessage());
        return "dea_testB";
    }


}
